﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GdHotel.Data.Interfaces;
using GdHotel.Data.Repositories;
using GdHotel.Web.Attributes;
using GdHotel.Web.Models;
using UniqueTechnologies.Attributes;
using UniqueTechnologies.Data.Interfaces;

namespace GdHotel.Web.Controllers
{
    [LayoutSupport]
    public class HomeController : BaseUiController
    {
        private const Int32 NewsCount = 4;
        private const String MainKey = "main";
        private const String MainGalleryKey = "biggallery";

        public override ILanguagesRepository LanguagesRepository { get; set; }
        public override INotesRepository NotesRepository { get; set; }
        public ICustomPagesRepository CustomPagesRepository { get; set; }
        public override IMainMenuItemsRepository MainMenuItemsRepository { get; set; }
        public INewsRepository NewsRepository { get; set; }
        public override IAdditionalMenuItemsRepository AdditionalMenuItemsRepository { get; set; }
        public IGalleriesRepository GalleriesRepository { get; set; }

        public HomeController(
            IAdditionalMenuItemsRepository additionalMenuItemsRepository,
            IGalleriesRepository galleriesRepository,
            ILanguagesRepository languagesRepository, 
            IMainMenuItemsRepository mainMenuItemsRepository,
            INewsRepository newsRepository,
            INotesRepository notesRepository,
            ICustomPagesRepository customPagesRepository)
        {
            LanguagesRepository = languagesRepository;
            NotesRepository = notesRepository;
            CustomPagesRepository = customPagesRepository;
            MainMenuItemsRepository = mainMenuItemsRepository;
            NewsRepository = newsRepository;
            AdditionalMenuItemsRepository = additionalMenuItemsRepository;
            GalleriesRepository = galleriesRepository;
        }

        //
        // GET: /Home/

        public ActionResult Index()
        {
            var gallery = GalleriesRepository.FindAllByKey(MainGalleryKey).FirstOrDefault();
            var roomsGallery = GalleriesRepository.FindAllByKey(MainKey).FirstOrDefault();
            var news = NewsRepository.GetLatestNewsByLang(Language, NewsCount);
            var page = CustomPagesRepository.FindAllByLangAndKey(Language, MainKey).FirstOrDefault();
            var note = NotesRepository.FindAllByLang(Language).FirstOrDefault();
            var model = new HomeModel { Gallery = gallery, RoomsGallery = roomsGallery, News = news, Page = page, Note = note};
            return View(model);
        }

    }
}
